package com.rongc.client.freight.base.view.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rongc.client.freight.R;
import com.rongc.client.freight.base.model.TipTemp;

import java.util.List;

/**
 * Created by ccqx on 2017/6/28.
 */

public class RecyclerMapAdapter extends RecyclerBaseAdapter<TipTemp>{
    static final int ITEM_TYPE = 0;
    static final int CLEAN_TYPE = 1;

    public RecyclerMapAdapter(Context mContext, List<TipTemp> mDatas) {
        super(mContext, mDatas);
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType){
            case ITEM_TYPE:
                view = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(), parent, false);
                break;
            case CLEAN_TYPE:
                view = new TextView(mContext,null,R.style.TextLabTitleLink);
                view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                ((TextView)view).setGravity(Gravity.CENTER);
                view.setPadding(10,10,10,10);
                view.setId(R.id.tv_desc);
                ((TextView)view).setText("清空历史记录");
                break;
        }
        return new BaseRecyclerViewHolder(view);
    }

    @Override
    protected void onBind(final BaseRecyclerViewHolder holder, int position, TipTemp data) {
        int type = getItemViewType(position);
        switch (type) {
            case ITEM_TYPE:
                holder.setText(R.id.tv_field, data.getName());
                holder.setText(R.id.tv_value, data.getAddress());
                break;
            case CLEAN_TYPE:
                break;
        }
    }

    @Override
    public int getItemViewType(int position) {
        if("-1" == mDatas.get(position).getPoiID()) return CLEAN_TYPE;
        return ITEM_TYPE;
    }


    @Override
    protected int getLayoutId() {
        return R.layout.recycler_map_item;
    }
}
